package jzoffer;

import leetcode.tree.TreeNode;

/**
 * @author wangmaolin1
 * @date 2021/12/5 下午6:11
 */
public class _28对称二叉树 {
    public boolean isSymmetric(TreeNode root) {
        if (root==null){
            return true;
        }

        return symmetric(root.left,root.right);
    }

    private boolean symmetric(TreeNode left, TreeNode right) {
        if (left==null&&right==null){
            return true;
        }
        if (left==null||right==null){
            return false;
        }
        if (left.val!=right.val){
            return false;
        }
        return symmetric(left.left,right.right) && symmetric(left.right,right.left);
    }
}
